package demo;

import org.hibernate.Session;
import org.hibernate.Transaction;

import bean.Book;
import bean.Dvd;

import util.HibMysqlSessionFactory;

public class InheritDemo {
	public static void main(String[] args) {
		Session session = HibMysqlSessionFactory.getSession();
		Transaction tx = null;
		try {
			tx = session.beginTransaction();
			Book book = new Book();
			book.setName("first book");
			book.setPageCount(100);
			Dvd dvd = new Dvd();
			dvd.setName("first dvd");
			dvd.setRegionCode("china");
			session.saveOrUpdate(book);
			session.saveOrUpdate(dvd);
			tx.commit();
		} catch (Exception e) {
			if (tx != null)
				tx.rollback();
			throw new RuntimeException(e);
		} finally {
			HibMysqlSessionFactory.closeSession();
		}
	}
}
